#include "head.h"

void* thread_main(void* p){

    status_t *status = (status_t*)p;

    //1.从队列中取出fd
    while (1){
        int net_fd = 0;
        pthread_mutex_lock(&status->mutex);

        //while (status->queue.size <= 0)
        while (status->queue.head == NULL)
        {
            pthread_cond_wait(&status->cond,&status->mutex);
        }
        
        net_fd = status->queue.head->net_fd;
        deQueue(&status->queue,&net_fd);

        pthread_mutex_unlock(&status->mutex);

        //2.和客户端通信
        do_worker(net_fd);

        close(net_fd);
        
    }
    return NULL;


}